package com.chang.annoValidation;

import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class TestUser {

    @Test
    public void Test1() {  // Validation原生接口测试
        ApplicationContext context = new AnnotationConfigApplicationContext(ValidationConfig.class);
        MyValidation validation = context.getBean(MyValidation.class);
        User user = new User();
        user.setName("AA");
        user.setAge(200);
        Boolean b = validation.validationTest(user);
        System.out.println(b); // 注意，这里输出的是字段校验是否合格，合格则为true
    }

    @Test
    public void Test2() { // spring框架集成Validation接口测试
        ApplicationContext context = new AnnotationConfigApplicationContext(ValidationConfig.class);
        MyValidationTwo validation = context.getBean(MyValidationTwo.class);
        User user = new User();
        user.setName("AA");
        user.setAge(120);
        boolean b = validation.ValidationTest(user);
        System.out.println(b); // 这里输出的是hasError 是否有异常，有异常则为true，也就是与原生接口反着来的
    }
}
